home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-30 | 10.7 KB | 539 lines | [TEXT/MPCC] |
-
- //============================================================================
- //----------------------------------------------------------------------------
- // Interface.c
- //----------------------------------------------------------------------------
- //============================================================================
-
-
- #include "Externs.h"
- #include <Sound.h>
-
-
- #define kAppleMenuID 128
- #define iAbout 1
- #define kGameMenuID 129
- #define iNewGame 1
- #define iPauseGame 2
- #define iEndGame 3
- #define iQuit 5
- #define kOptionsMenuID 130
- #define iSettings 1
- #define iHelp 2
- #define iHighScores 3
- #define kAboutPictID 132
-
-
- void DoAppleMenu (short);
- void DoGameMenu (short);
- void DoOptionsMenu (short);
- void UpdateMainWindow (void);
- void HandleMouseEvent (EventRecord *);
- void HandleKeyEvent (EventRecord *);
- void HandleUpdateEvent (EventRecord *);
- void HandleOSEvent (EventRecord *);
- void HandleHighLevelEvent (EventRecord *);
- void DoAbout (void);
- void DoGameSettings (void);
-
-
- Rect mainWindowRect;
- WindowPtr mainWindow;
- MenuHandle appleMenu, gameMenu, optionsMenu;
- Boolean switchedOut, quitting, canPlay, openTheScores;
-
- extern prefsInfo thePrefs;
- extern Rect backSrcRect, workSrcRect;
- extern CGrafPtr backSrcMap, workSrcMap;
- extern Boolean pausing, playing, helpOpen, scoresOpen;
-
-
- //============================================================== Functions
- //-------------------------------------------------------------- MenusReflectMode
-
- void MenusReflectMode (void)
- {
- if (playing)
- {
- DisableItem(gameMenu, iNewGame);
- EnableItem(gameMenu, iPauseGame);
- if (pausing)
- SetItem(gameMenu, iPauseGame, "\pResume Game");
- else
- SetItem(gameMenu, iPauseGame, "\pPause Game");
- EnableItem(gameMenu, iEndGame);
- DisableItem(optionsMenu, 0);
- }
- else
- {
- EnableItem(gameMenu, iNewGame);
- DisableItem(gameMenu, iPauseGame);
- SetItem(gameMenu, iPauseGame, "\pPause Game");
- DisableItem(gameMenu, iEndGame);
- EnableItem(optionsMenu, 0);
- }
- }
-
- //-------------------------------------------------------------- DoAppleMenu
-
- void DoAppleMenu (short theItem)
- {
- Str255 daName;
- GrafPtr wasPort;
- short daNumber;
-
- switch (theItem)
- {
- case iAbout:
- if ((scoresOpen) || (helpOpen))
- {
- CloseWall();
- scoresOpen = FALSE;
- helpOpen = FALSE;
- CheckItem(optionsMenu, iHelp, helpOpen);
- CheckItem(optionsMenu, iHighScores, scoresOpen);
- }
- DoAbout();
- break;
-
- default:
- GetItem(appleMenu, theItem, daName);
- GetPort(&wasPort);
- daNumber = OpenDeskAcc(daName);
- SetPort((GrafPtr)wasPort);
- break;
- }
- }
-
- //-------------------------------------------------------------- DoGameMenu
-
- void DoGameMenu (short theItem)
- {
- switch (theItem)
- {
- case iNewGame:
- if ((scoresOpen) || (helpOpen))
- {
- CloseWall();
- scoresOpen = FALSE;
- helpOpen = FALSE;
- CheckItem(optionsMenu, iHelp, helpOpen);
- CheckItem(optionsMenu, iHighScores, scoresOpen);
- }
- InitNewGame();
- MenusReflectMode();
- break;
-
- case iPauseGame:
- if (pausing)
- {
- pausing = FALSE;
- DumpBackToWorkMap();
- }
- break;
-
- case iEndGame:
- break;
-
- case iQuit:
- quitting = TRUE;
- break;
- }
- }
-
- //-------------------------------------------------------------- DoOptionsMenu
-
- void DoOptionsMenu (short theItem)
- {
- switch (theItem)
- {
- case iSettings:
- if ((scoresOpen) || (helpOpen))
- {
- CloseWall();
- scoresOpen = FALSE;
- helpOpen = FALSE;
- CheckItem(optionsMenu, iHelp, helpOpen);
- CheckItem(optionsMenu, iHighScores, scoresOpen);
- }
- DoGameSettings();
- break;
-
- case iHelp:
- if (helpOpen)
- {
- CloseWall();
- helpOpen = FALSE;
- }
- else
- {
- if (scoresOpen)
- {
- CloseWall();
- scoresOpen = FALSE;
- CheckItem(optionsMenu, iHighScores, scoresOpen);
- }
- OpenHelp();
- }
- CheckItem(optionsMenu, iHelp, helpOpen);
- break;
-
- case iHighScores:
- if (scoresOpen)
- {
- CloseWall();
- scoresOpen = FALSE;
- }
- else
- {
- if (helpOpen)
- {
- CloseWall();
- helpOpen = FALSE;
- CheckItem(optionsMenu, iHelp, helpOpen);
- }
- OpenHighScores();
- }
- CheckItem(optionsMenu, iHighScores, scoresOpen);
- break;
- }
- }
-
- //-------------------------------------------------------------- DoMenuChoice
-
- void DoMenuChoice (long menuChoice)
- {
- short theMenu, theItem;
-
- if (menuChoice == 0)
- return;
-
- theMenu = HiWord(menuChoice);
- theItem = LoWord(menuChoice);
-
- switch (theMenu)
- {
- case kAppleMenuID:
- DoAppleMenu(theItem);
- break;
-
- case kGameMenuID:
- DoGameMenu(theItem);
- break;
-
- case kOptionsMenuID:
- DoOptionsMenu(theItem);
- break;
- }
-
- HiliteMenu(0);
- }
-
- //-------------------------------------------------------------- UpdateMainWindow
-
- void UpdateMainWindow (void)
- {
- CopyBits(&((GrafPtr)backSrcMap)->portBits,
- &(((GrafPtr)mainWindow)->portBits),
- &mainWindowRect, &mainWindowRect,
- srcCopy, 0L);
- }
-
- //-------------------------------------------------------------- HandleMouseEvent
-
- void HandleMouseEvent (EventRecord *theEvent)
- {
- WindowPtr whichWindow;
- long menuChoice;
- short thePart;
-
- thePart = FindWindow(theEvent->where, &whichWindow);
-
- switch (thePart)
- {
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
-
- case inMenuBar:
- menuChoice = MenuSelect(theEvent->where);
- if (canPlay)
- DoMenuChoice(menuChoice);
- break;
-
- case inDrag:
- case inGoAway:
- case inGrow:
- case inZoomIn:
- case inZoomOut:
- break;
-
- case inContent:
- FlashObelisks(TRUE);
- LogNextTick(3);
- GenerateLightning(theEvent->where.h, theEvent->where.v - 20);
- StrikeLightning();
- WaitForNextTick();
- StrikeLightning();
- LogNextTick(2);
- WaitForNextTick();
- PlayExternalSound(kLightningSound, kLightningPriority);
- LogNextTick(3);
- GenerateLightning(theEvent->where.h, theEvent->where.v - 20);
- StrikeLightning();
- WaitForNextTick();
- StrikeLightning();
- LogNextTick(2);
- WaitForNextTick();
- LogNextTick(3);
- GenerateLightning(theEvent->where.h, theEvent->where.v - 20);
- StrikeLightning();
- WaitForNextTick();
- StrikeLightning();
- LogNextTick(2);
- WaitForNextTick();
- PlayExternalSound(kLightningSound, kLightningPriority);
- LogNextTick(3);
- GenerateLightning(theEvent->where.h, theEvent->where.v - 20);
- StrikeLightning();
- WaitForNextTick();
- StrikeLightning();
- LogNextTick(2);
- WaitForNextTick();
- FlashObelisks(FALSE);
- break;
- }
- }
-
- //-------------------------------------------------------------- HandleKeyEvent
-
- void HandleKeyEvent (EventRecord *theEvent)
- {
- char theChar;
- Boolean commandDown;
-
- theChar = theEvent->message & charCodeMask;
- commandDown = ((theEvent->modifiers & cmdKey) != 0);
-
- if (commandDown)
- {
- if (canPlay)
- DoMenuChoice(MenuKey(theChar));
- }
- else
- {
- if (helpOpen)
- {
- if (theChar == kUpArrowKeyASCII)
- {
- if (theEvent->what == autoKey)
- ScrollHelp(-3);
- else
- ScrollHelp(-1);
- }
- else if (theChar == kDownArrowKeyASCII)
- {
- if (theEvent->what == autoKey)
- ScrollHelp(3);
- else
- ScrollHelp(1);
- }
- else if (theChar == kPageDownKeyASCII)
- {
- ScrollHelp(199);
- }
- else if (theChar == kPageUpKeyASCII)
- {
- ScrollHelp(-199);
- }
- else if ((theChar == kHelpKeyASCII) && (!playing))
- {
- CloseWall();
- helpOpen = FALSE;
- CheckItem(optionsMenu, iHelp, helpOpen);
- }
- }
- else if ((theChar == kHelpKeyASCII) && (!playing))
- {
- if (scoresOpen)
- {
- CloseWall();
- scoresOpen = FALSE;
- CheckItem(optionsMenu, iHighScores, scoresOpen);
- }
- OpenHelp();
- CheckItem(optionsMenu, iHelp, helpOpen);
- }
- }
- }
-
- //-------------------------------------------------------------- HandleUpdateEvent
-
- void HandleUpdateEvent (EventRecord *theEvent)
- {
- if ((WindowPtr)theEvent->message == mainWindow)
- {
- SetPort((GrafPtr)mainWindow);
- BeginUpdate((GrafPtr)mainWindow);
- UpdateMainWindow();
- EndUpdate((GrafPtr)mainWindow);
- canPlay = TRUE;
- }
- }
-
- //-------------------------------------------------------------- HandleOSEvent
-
- void HandleOSEvent (EventRecord *theEvent)
- {
- if (theEvent->message & 0x01000000) // suspend or resume event
- {
- if (theEvent->message & 0x00000001) // resume event
- {
- switchedOut = FALSE;
- }
- else // suspend event
- {
- switchedOut = TRUE;
- }
- }
- }
-
- //-------------------------------------------------------------- HandleHighLevelEvent
-
- void HandleHighLevelEvent (EventRecord *theEvent)
- {
- // theErr = AEProcessAppleEvent(theEvent);
- }
-
- //-------------------------------------------------------------- HandleEvent
-
- void HandleEvent (void)
- {
- EventRecord theEvent;
- long sleep = 1L;
- Boolean itHappened;
-
- itHappened = WaitNextEvent(everyEvent, &theEvent, sleep, 0L);
-
- if (itHappened)
- {
- switch (theEvent.what)
- {
- case mouseDown:
- HandleMouseEvent(&theEvent);
- break;
-
- case keyDown:
- case autoKey:
- HandleKeyEvent(&theEvent);
- break;
-
- case updateEvt:
- HandleUpdateEvent(&theEvent);
- break;
-
- case osEvt:
- HandleOSEvent(&theEvent);
- break;
-
- case kHighLevelEvent:
- HandleHighLevelEvent(&theEvent);
- break;
- }
- }
- else if (openTheScores)
- {
- openTheScores = FALSE;
- OpenHighScores();
- }
- }
-
- //-------------------------------------------------------------- DoAbout
-
- void DoAbout (void)
- {
- Rect aboutRect;
- WindowPtr aboutWindow;
-
- SetRect(&aboutRect, 0, 0, 325, 318);
- CenterRectInRect(&aboutRect, &qd.screenBits.bounds);
- aboutWindow = GetNewCWindow(129, 0L, kPutInFront);
- MoveWindow((GrafPtr)aboutWindow, aboutRect.left, aboutRect.top, TRUE);
- ShowWindow((GrafPtr)aboutWindow);
- SetPort((GrafPtr)aboutWindow);
- LoadGraphic(kAboutPictID);
-
- do
- {
- }
- while (Button());
- do
- {
- }
- while (!Button());
-
- FlushEvents(everyEvent, 0);
-
- if (aboutWindow != 0L)
- DisposeWindow(aboutWindow);
- }
-
- //-------------------------------------------------------------- DoGameSettings
-
- void DoGameSettings (void)
- {
- #define kGameSettingsDialogID 133
- DialogPtr theDial;
- long newVolume;
- short i, item;
- Boolean leaving;
-
- CenterDialog(kGameSettingsDialogID);
- theDial = GetNewDialog(kGameSettingsDialogID, 0L, kPutInFront);
- SetPort((GrafPtr)theDial);
- ShowWindow((GrafPtr)theDial);
- DrawDefaultButton(theDial);
- FlushEvents(everyEvent, 0);
-
- SetDialogNumToStr(theDial, 3, (long)thePrefs.wasVolume);
- SelIText(theDial, 3, 0, 1024);
-
- leaving = FALSE;
-
- while (!leaving)
- {
- ModalDialog(0L, &item);
-
- if (item == 1)
- {
- GetDialogNumFromStr(theDial, 3, &newVolume);
- if ((newVolume >= 0) && (newVolume <= 7))
- {
- thePrefs.wasVolume = (short)newVolume;
- SetSoundVol((short)newVolume);
- leaving = TRUE;
- }
- else
- {
- SysBeep(1);
- SetDialogNumToStr(theDial, 3, (long)thePrefs.wasVolume);
- SelIText(theDial, 3, 0, 1024);
- }
- }
- else if (item == 2)
- {
- for (i = 0; i < 10; i++)
- {
- PasStringCopy("\pNemo", thePrefs.highNames[i]);
- thePrefs.highScores[i] = 0L;
- thePrefs.highLevel[i] = 0;
- openTheScores = TRUE;
- }
- DisableControl(theDial, 2);
- }
- }
-
- DisposDialog(theDial);
- }
-
-